from abc import ABC, abstractmethod


class FileSystemComponent(ABC):
    @abstractmethod
    def display(self):
        pass


class File(FileSystemComponent):
    def __init__(self, name):
        self.name = name

    def display(self):
        print(f"File:{self.name}")


class Directory(FileSystemComponent):
    def __init__(self, name):
        self.name = name
        self.children = []

    def add(self, component):
        self.children.append(component)

    def remove(self, component):
        self.children.remove(component)

    def display(self):
        for child in self.children:
            child.display()


# 创建文件和文件夹
file1 = File("File1.txt")
file2 = File("File2.txt")
dir1 = Directory("Directory1")
dir2 = Directory("Directory2")

# 组合文件和文件夹
dir1.add(file1)
dir2.add(file2)
dir2.add(dir1)

# 显示结构
file1.display()
print('*' * 30)
file2.display()
print('*' * 30)
dir1.display()
print('*' * 30)
dir2.display()

'''
File:File1.txt
******************************
File:File2.txt
******************************
File:File1.txt
******************************
File:File2.txt
File:File1.txt
'''
